// components/playlist/playlist.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    playlist:{
      type:Object,
      default: () => {}
    }
  },
  observers:{
    'playlist.playCount'(val) {
      this.setData({
        count:this.transformNum(val)
      })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    count:0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 数量转换
     */
    transformNum(num,precision = 2) {
      let strNum = num.toString().split('.')[0]
      let strLen = strNum.length
      if (strLen < 6) {
        return strNum
      } else if (strLen >= 6 && strLen <= 8) {
        let decimal = strNum.substring(strLen - 6,strLen - 6 + precision)
        return parseInt(strNum / 10000) + '.' + decimal + '万'
      } else {
        let decimal = strNum.substring(strLen - 8,strLen - 8 + precision)
        return parseInt(strNum / 100000000) + '.' + decimal + '亿'
      }
    },
    /**
     * 点击事件
     */
    handleTapClick() {
      wx.navigateTo({
        url: `../../pages/musiclist/musiclist?playlistId=${this.properties.playlist.id}`,
      })
    }
  }
})
